#include <iostream>
#include <vector>
#include <climits>
using namespace std;
 
int main()
{
    int V = 0, n = 0;
    cin >> V >> n;
    vector<int> arr(n);    // 下面找原数组不-1的话就多开一个位置占位，输入[1,n]
    for(int i = 0; i < n; ++i)
    {
        cin >> arr[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(V + 1));
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= V; ++j)
        {
            dp[i][j] = dp[i - 1][j];
            if(j >= arr[i - 1])
                dp[i][j] = max(dp[i][j], dp[i - 1][j - arr[i - 1]] + arr[i - 1]);
        }
    }
    cout << V - dp[n][V] << endl;
    return 0;
}